#ifndef ROS_WEB_BRIDGE__ROS_WEB_BRIDGE_HPP_
#define ROS_WEB_BRIDGE__ROS_WEB_BRIDGE_HPP_

#include "pcl/point_cloud.h"
#include "pcl/point_types.h"
#include "rclcpp/rclcpp.hpp"
#include "sensor_msgs/msg/point_cloud2.hpp"

namespace ros_web_bridge
{
class RosWebBridgeNode : public rclcpp::Node
{
public:
  explicit RosWebBridgeNode(const rclcpp::NodeOptions & options);

private:
  //点云消息订阅回调
  void laserCloudHandler(const sensor_msgs::msg::PointCloud2::ConstSharedPtr laserCloud2);
  // 将 pcl::PointCloud<pcl::PointXYZI> 转成二进制字节数组
  std::vector<uint8_t> serializePointCloud(pcl::PointCloud<pcl::PointXYZI>::Ptr cloud);
  // 使用 zlib 进行 gzip 压缩
  std::string compressGzip(const std::vector<uint8_t> & input);
  // 使用TCP发送
  void sendToClient(
    std::vector<unsigned char, std::allocator<unsigned char>> compressed_data, const std::string & ip = "192.168.1.50", int port = 9999);

  std::shared_ptr<pcl::PointCloud<pcl::PointXYZI>> laser_cloud_;

  rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr laser_cloud_sub_;
};
}  // namespace ros_web_bridge

#endif